//
//  ListViewCell.m
//  BaseAPP
//
//  Created by Evisu on 16/12/19.
//  Copyright © 2016年 evisum. All rights reserved.
//

#import "ListViewCell.h"

@interface ListViewCell ()

@property (nonatomic, strong)UIView *vBottomLine;

@end

@implementation ListViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self initViews];
        [self layoutViews];
        
        self.model = [NSArray array];
    }
    
    return self;
}

- (void)initViews {

    self.backgroundColor = [UIColor clearColor];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.btnItem = [[ListBtn alloc] init];
    self.btnItem.titleLabel.font = [UIFont systemFontOfSize:14.0];
    self.btnItem.adjustsImageWhenHighlighted = NO;
    [self.btnItem setBackgroundImage:[UIImage imageWithColor:HEXColor(@"424143")] forState:UIControlStateHighlighted];
    [self.btnItem setTitleColor:HEXColor(@"fbfbfb") forState:UIControlStateNormal];
    [self.btnItem addTarget:self action:@selector(didClickedItem:) forControlEvents:UIControlEventTouchUpInside];
    
    self.vBottomLine = [[UIView alloc] init];
    self.vBottomLine.backgroundColor = HEXColor(@"525154");
    
    [self.contentView addSubview:self.btnItem];
    [self.contentView addSubview:self.vBottomLine];
}


- (void)layoutViews {
    
    self.btnItem.sd_layout
    .topEqualToView(self.contentView)
    .leftSpaceToView(self.contentView, 6)
    .rightSpaceToView(self.contentView, 6)
    .bottomEqualToView(self.contentView);
    
    self.vBottomLine.sd_layout
    .bottomEqualToView(self.contentView)
    .leftSpaceToView(self.contentView, 14)
    .rightSpaceToView(self.contentView, 14)
    .heightIs(1);
}

- (void)setModel:(NSArray *)model {

    _model = model;

    if (model.count > 0) {
        
        [self.btnItem setImage:[UIImage imageNamed:model.lastObject] forState:UIControlStateNormal];
        [self.btnItem setTitle:model.firstObject forState:UIControlStateNormal];
    }
    
}

- (void)didClickedItem:(UIButton *)btn {

    if (self.listBlock) {
        
        self.listBlock(btn.tag);
    }
}

@end
